Skip to content

feat: add C implementation for stats/base/dists/f/pdf#11201

Merged
Planeshifter merged 3 commits into
stdlib-js:developfrom
rautelaKamal:feat/stats-base-dists-f-pdf-c-port
Jul 5, 2026
Merged

feat: add C implementation for stats/base/dists/f/pdf#11201
Planeshifter merged 3 commits into
stdlib-js:developfrom
rautelaKamal:feat/stats-base-dists-f-pdf-c-port

Conversation

@rautelaKamal

@rautelaKamal rautelaKamal commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • Implements a native C-port for the F Distribution Probability Density Function (@stdlib/stats/base/dists/f/pdf).
  • Configures include.gypi, binding.gyp, and manifest.json dependencies via internal N-API mechanisms (STDLIB_MATH_BASE_NAPI_MODULE_DDD_D).
  • Validates identical sub-epsilon behavior to pure JS implementation across boundaries, limits, and NaN.
  • Introduces robust Boost and Julia test.native.js fixtures to validate the C-port accuracy and benchmarks it.

Related Issues

Does this pull request have any related issues?

This pull request has no related issues.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

This is a Proof of Concept submission towards my GSoC 2026 application regarding porting distributions and specific math functions to high-performance C native addons.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Mar 29, 2026
@stdlib-bot

stdlib-bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/f/pdf $\\color{red}599/647$
$\\color{green}+0.00\\%$
$\\color{red}62/66$
$\\color{green}+0.00\\%$
$\\color{green}6/6$
$\\color{green}+0.00\\%$
$\\color{red}599/647$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@rautelaKamal

Copy link
Copy Markdown
Contributor Author

Just a quick heads up regarding the minor coverage drop flagged by Codecov:

The native.js file is showing 0% function coverage because the addon.node binary correctly skips compilation during the CI coverage step, which triggers the expected opts.skip = true fallback inside test.native.js. The math logic is fully tested and verified when the native addon actually builds!

Also, the drop in ibeta_power_terms.js relates to the original pure JavaScript implementations and was untouched in this PR. @Planeshifter

@Neerajpathak07

Copy link
Copy Markdown
Member

@rautelaKamal FYI: I think you have misunderstood what we do for adding native implementation. Here we expect to add the corresponding C files for benchmark, examples and the main implementation alongside the relevant dependencies and documentations.
Take a look at a few of the merged PR's on how this is done.
For eg:- refer to https://github.com/stdlib-js/stdlib/pull/10839/changes

@rautelaKamal

Copy link
Copy Markdown
Contributor Author

@Neerajpathak07 Thank you for catching this and pointing me to the reference PR! I totally misunderstood the scope, I was focused solely on evaluating the N-API/Node.js boundary and completely neglected the standalone C ecosystem deliverables.

I have just pushed an update that adds the benchmark/c/ and examples/c/ directories, the src/Makefile for cleanup, and the full C APIs documentation section in the README.md.

Really appreciate you taking the time to explain the standard.Please let me know if there's anything else I missed!

@Lokeshranjan8

Lokeshranjan8 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

@rautelaKamal Update your commit message

feat(stats/base/dists/f/pdf): add native C addon for evaluating the PDF

to the following

feat: add C implementation for stats/base/dists/f/pdf

@rautelaKamal rautelaKamal force-pushed the feat/stats-base-dists-f-pdf-c-port branch from 9744905 to 197e55f Compare March 31, 2026 18:19
@rautelaKamal rautelaKamal changed the title feat(stats/base/dists/f/pdf): add native C addon for evaluating the PDF feat: add C implementation for stats/base/dists/f/pdf Apr 4, 2026
@rautelaKamal rautelaKamal force-pushed the feat/stats-base-dists-f-pdf-c-port branch from 8be84d0 to 4bf98b2 Compare April 5, 2026 18:44
@stdlib-bot stdlib-bot added the Merge Conflicts Pull request which has merge conflicts. label Apr 7, 2026
@rautelaKamal rautelaKamal force-pushed the feat/stats-base-dists-f-pdf-c-port branch from 4bf98b2 to 68e429f Compare April 7, 2026 11:49
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Apr 7, 2026
@rautelaKamal rautelaKamal reopened this Apr 12, 2026
@stdlib-bot stdlib-bot removed the Merge Conflicts Pull request which has merge conflicts. label Apr 14, 2026
@rautelaKamal rautelaKamal force-pushed the feat/stats-base-dists-f-pdf-c-port branch from e73fb48 to 0f35a65 Compare April 14, 2026 18:28
@rautelaKamal rautelaKamal requested a review from a team April 20, 2026 13:13
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Apr 20, 2026
@Planeshifter Planeshifter force-pushed the feat/stats-base-dists-f-pdf-c-port branch from b97480f to 647e413 Compare July 5, 2026 05:35
rautelaKamal and others added 3 commits July 5, 2026 01:16
The C usage example in both the README and the `src/main.c` `@example`
annotated `stdlib_base_dists_f_pdf( 2.0, 1.0, 1.0 )` as returning
`~0.127`, but the correct value is `~0.075`. Since CI does not execute
C example comments, the error would otherwise ship. A baseline
assertion mirroring the corrected value is added to the native test to
guard against regressions.

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
The native C implementation computes the log-PDF via betaln+exp, which
differs from the JS reference value by 2 ULP for pdf(2,1,1). The baseline
assertion used a 1-ULP tolerance, causing the native test to fail in CI.

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter Planeshifter force-pushed the feat/stats-base-dists-f-pdf-c-port branch from 647e413 to 2ff7ac9 Compare July 5, 2026 06:16
@Planeshifter Planeshifter changed the title feat: add C implementation for stats/base/dists/f/pdf feat: add C implementation for stats/base/dists/f/pdf Jul 5, 2026

@Planeshifter Planeshifter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last but not least, let's land this PR of yours, @rautelaKamal!

@Planeshifter Planeshifter added the Ready To Merge A pull request which is ready to be merged. label Jul 5, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

PR Commit Message

feat: add C implementation for `stats/base/dists/f/pdf`

PR-URL: https://github.com/stdlib-js/stdlib/pull/11201

Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>

Please review the above commit message and make any necessary adjustments.

@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jul 5, 2026
@Planeshifter Planeshifter merged commit 82d0e4a into stdlib-js:develop Jul 5, 2026
35 checks passed
@stdlib-bot stdlib-bot removed the Ready To Merge A pull request which is ready to be merged. label Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants